﻿using B.S.Sterilizationcenter.Domain.zmc;
using B.S.Sterilizationcenter.ErrorCode;
using B.S.Sterilizationcenter.Read.API.Appliaction.Commends.zmc.Instrumentkit;
using B.S.Sterilizationcenter.Read.API.Dto;
using MediatR;
using SqlSugar;

namespace B.S.Sterilizationcenter.Read.API.Appliaction.CommandHandlers.zmc.Instrumentkit
{
    public class QueryInstrumentkitApparaCommendHandlers : IRequestHandler<QueryInstrumentkitApparaCommends, ApiResult<List<ApparaInstrumentkitDtos>>>
    {
        private readonly ISqlSugarClient db;

        public QueryInstrumentkitApparaCommendHandlers(ISqlSugarClient db)
        {
            this.db = db;
        }

        /// <summary>
        /// 显示器械数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<List<ApparaInstrumentkitDtos>>> Handle(QueryInstrumentkitApparaCommends request, CancellationToken cancellationToken)
        {
            ApiResult<List<ApparaInstrumentkitDtos>> result= new ApiResult<List<ApparaInstrumentkitDtos>>();
            result.Code = ApiEnums.查询成功;
            result.Msg = "查询成功";
            var data = db.Queryable<Apparatus, Instrumentkits>((a, b) => a.ApparatusNo == b.InstrumentkitsNo).Select((a, b) => new ApparaInstrumentkitDtos
            {
                ApparatusId = a.ApparatusId,
                ApparatusNo = a.ApparatusNo,
                ApparatusName = a.ApparatusName,
                    Specification = a.Specification,
                    Quantity = a.Quantity,
                    Durableproperties = a.Durableproperties,
                InstrumentkitsNo = b.InstrumentkitsNo,

            }).ToList();
            result.Data = data;
            return result;
        }
    }
}
